
import pytest


from core.api_util import api_util
from utils.read import base_data



def get_data():
    return base_data.read_data()

def get_data_recruit():
    return base_data.read_data_recruit()

# cookies 获取
@pytest.fixture(scope="session")
def login_cookies():
    json_data = get_data()['user_login']
    result = login_fix(json_data)

    print(result)
    return result
def login_fix(json_data):
    """
    后台登录
    :param json_data:
    :return:
    """
    header = {
        "platformid": "4"
    }
    response = api_util.post_data(headers=header,json=json_data)
    return response.cookies


# header 传递
@pytest.fixture(scope="session")
def header_fixture():
    header = {
        "platformid": "4"
    }
    return header

#
# def login_fix(json_data):
#     """
#     后台登录
#     :param json_data:
#     :return:
#     """
#     header = {
#         "platformid": "4"
#     }
#     response = api_util.post_data(headers=header,json=json_data)
#     print("Login response headers:", response.headers)
#     print("Request headers:", response.request.headers)  # 更正打印语句
#
#     # 将 RequestsCookieJar 转换成字典
#     cookies_dict = dict_from_cookiejar(response.cookies)
#
#     # 返回 RequestsCookieJar 形式的 cookies
#     return cookiejar_from_dict(cookies_dict)
#
#
# # 如果你需要将 cookies 序列化为 JSON 并持久化，可以使用以下代码
# def save_cookies_to_file(cookies_jar, filename='cookies.json'):
#     cookies_dict = dict_from_cookiejar(cookies_jar)
#     with open(filename, 'w') as file:
#         json.dump(cookies_dict, file)
#
#
# # 如果你需要从文件中加载 cookies 并转换回 RequestsCookieJar，可以使用以下代码
# def load_cookies_from_file(filename='cookies.json'):
#     with open(filename, 'r') as file:
#         cookies_dict = json.load(file)
#     return cookiejar_from_dict(cookies_dict)